package com.seuic.hnjiningposapp.hnapps.ui.activity;

import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import androidx.appcompat.app.AlertDialog;
import androidx.cardview.widget.CardView;

import com.alibaba.fastjson.JSONObject;
import com.blankj.utilcode.util.SPStaticUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.lxj.xpopup.XPopup;
import com.lxj.xpopup.core.BasePopupView;
import com.seuic.hnjiningposapp.R;
import com.seuic.hnjiningposapp.hnapps.base.BaseActivity;
import com.seuic.hnjiningposapp.hnapps.bean.ZzhBean;
import com.seuic.hnjiningposapp.hnapps.ui.view.dialog.AutomaticOperationPopup;
import com.seuic.hnjiningposapp.hnapps.ui.view.dialog.DealingPopup;
import com.seuic.hnjiningposapp.hnapps.ui.view.dialog.DtoHClientInputMoneyPp;
import com.seuic.hnjiningposapp.hnapps.ui.view.dialog.DtoHClientinfoPp;
import com.seuic.hnjiningposapp.hnapps.ui.view.dialog.DtohSuccessPp;
import com.seuic.hnjiningposapp.hnapps.ui.view.dialog.ErrorPopup;
import com.seuic.hnjiningposapp.hnapps.ui.view.dialog.HtoDSuccessPp;
import com.seuic.hnjiningposapp.hnapps.ui.view.dialog.InputPasswordPopup;
import com.seuic.hnjiningposapp.hnapps.ui.view.dialog.PrintingPopup;
import com.seuic.hnjiningposapp.hnapps.ui.view.dialog.ReadCardPopup;
import com.seuic.hnjiningposapp.hnapps.ui.view.dialog.RemittancePopup;
import com.seuic.hnjiningposapp.hnapps.ui.view.dialog.SelHtoDSaveTimePp;
import com.seuic.hnjiningposapp.hnapps.ui.view.dialog.SelHtoDSaveTypePp;
import com.seuic.hnjiningposapp.hnapps.ui.view.dialog.SureDtoHinfoPp;
import com.seuic.hnjiningposapp.hnapps.ui.view.dialog.SureHtoDInfoPp;
import com.seuic.hnjiningposapp.hnapps.ui.view.dialog.SurePrintPopup;
import com.seuic.hnjiningposapp.hnapps.ui.view.dialog.VerifyCardPopup;
import com.seuic.hnjiningposapp.hnapps.util.GetMoneyLvUtils;
import com.seuic.hnjiningposapp.hnapps.util.HttpUtils;
import com.seuic.hnjiningposapp.hnapps.util.HttpUtilsV2;
import com.seuic.hnjiningposapp.hnapps.util.PrintUtil;
import com.seuic.hnjiningposapp.hnapps.util.TimeUtils;
import com.seuic.hnjiningposapp.hnapps.util.UiTool;
import com.seuic.posdsdk.pos_func.PosFuncs;
import com.socks.library.KLog;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 定活互转
 */
public class ConstantrotationActivity extends BaseActivity implements DtoHClientInputMoneyPp.DtoHClientInputCall, ErrorPopup.OnFinishCallbacked, DtohSuccessPp.DtohSuccessCallBack, SureDtoHinfoPp.SureDtoHCallBack, DtoHClientinfoPp.SelDtoHlist, SurePrintPopup.ClickCallback, HtoDSuccessPp.HtoDSuccessCallBack, SureHtoDInfoPp.OnSureCallHtoDBack, SelHtoDSaveTimePp.CallBackHtoDinfo, SelHtoDSaveTypePp.onSelSaveType, InputPasswordPopup.ClickCallback {
    //选择类型
    public static String SAVE_TYPE;
    //活转定 整存整取
    public static final String HTOD_SElALLTYPE = "HTOD_SElALLTYPE";
    //活转定 智能存
    public static final String HTOD_CAPACITYTYPE = "HTOD_SElALLTYPE";
    //自动转存
    public static boolean HTOD_UNLADING = true;

    //本息转存
    public static final String BX = "BX_UNLADING";
    //本金转存
    public static final String BJ = "BJ_UNLADING";
    private PosFuncs posFuncs;
    //活转定  true    定转活  false
    private boolean HtoD = true;

    @BindView(R.id.live_to_atfixedperiod_btn)
    Button liveToAtfixedperiodBtn;
    @BindView(R.id.atfixedperiod_to_live_btn)
    Button atfixedperiodToLiveBtn;
    @BindView(R.id.home_card_layout)
    CardView homeCardLayout;//定活互转

    private ReadCardPopup readcardPop;
    private BasePopupView readcardPopupView;
    private VerifyCardPopup verifycardPop;
    private BasePopupView verifycardPopupView;
    private InputPasswordPopup inputpasswordPop;
    private BasePopupView inputpasswordPopupView;
    private BaseActivity baseActivity;
    private AutomaticOperationPopup automaticOperationPopup;
    private BasePopupView automaticOperationPopupView;
    private String card_num;
    private SelHtoDSaveTypePp selHtoDSaveTypePp;
    private BasePopupView selHtoDSaveTypePpView;
    private SelHtoDSaveTimePp selHtoDSaveTimePp;
    private BasePopupView selHtoDSaveTimePpView;
    private SureHtoDInfoPp sureHtoDInfoPp;
    private BasePopupView sureHtoDInfoPpView;
    private DealingPopup dealingPop;
    private BasePopupView dealingPopupView;
    private HtoDSuccessPp htoDSuccessPp;
    private BasePopupView htoDSuccessPpView;
    private SurePrintPopup surePrintPop;
    private PrintingPopup printingPop;
    private BasePopupView surePrintPopupView;
    private BasePopupView printingPopupView;
    private DtoHClientinfoPp dtoHClientinfoPp;
    private BasePopupView dtoHClientinfoPpView;
    private SureDtoHinfoPp sureDtoHinfoPp;
    private BasePopupView sureDtoHinfoPpView;
    private DtohSuccessPp dtohSuccessPp;
    private BasePopupView dtohSuccessPpView;
    private ErrorPopup errorPopup;
    private BasePopupView errorPopupPpView;
    //加密获得的密码
    private String cipassword;
    //查询出来的  子账户
    private List<ZzhBean> zzhBeans = new ArrayList<>();
    private List<ZzhBean> newzzhBeans;
    //用户证件号码
    private String certNo;
    //证件类型
    private String certType;
    //用户名
    private String card_username;
    private String pdp_codEs;
    private String seq_nOs;
    private String dtoHmoneys;
    private String make_time;
    private String mServerSeqNo;
    private ZzhBean returnzzhBean1;
    //支取后账户剩余金额
    String accBal = "";

    private RemittancePopup remittancePop;
    private BasePopupView remittancePopupView;
    private String userBalance;
    private String htodtime;
    private String htodMoney;
    private String htodrateOfInterest;
    private String htodinterest;
    private String htodtotal;
    private String htodZcTag;

    private String track2Data;
    private String htodProductCode;
    private String htodName;

    //活转定返回笔号
    private String htodPenNum;
    //活转定到期日期
    private String htodEndTime;
    private String htodTag;
    private DtoHClientInputMoneyPp dtoHClientInputMoneyPp;
    private BasePopupView dtoHClientInputMoneyPpView;
    private String intInt;

    @Override
    public int initView(Bundle savedInstanceState) {
        return R.layout.activity_constantrotation;
    }

    @Override
    public void initData(Bundle savedInstanceState) {
        setBackBtClick(R.id.base_back_btn);
        setTitleText("定活互转");
        findViewById(R.id.base_back_btn).setVisibility(View.INVISIBLE);
        errorPopup = new ErrorPopup(this, this);
        errorPopupPpView = new XPopup.Builder(this)
                .dismissOnBackPressed(false)
                .dismissOnTouchOutside(false)
                .moveUpToKeyboard(false)
                .isRequestFocus(false)
                .hasShadowBg(false)
                .hasStatusBarShadow(false)
                .asCustom(errorPopup);
        dtohSuccessPp = new DtohSuccessPp(this, this);
        dtohSuccessPpView = new XPopup.Builder(this)
                .dismissOnBackPressed(false)
                .dismissOnTouchOutside(false)
                .moveUpToKeyboard(false)
                .isRequestFocus(false)
                .hasShadowBg(false)
                .hasStatusBarShadow(false)
                .asCustom(dtohSuccessPp);//定转活成功

        dtoHClientinfoPp = new DtoHClientinfoPp(this, this);
        dtoHClientinfoPpView = new XPopup.Builder(this)
                .dismissOnBackPressed(false)
                .dismissOnTouchOutside(false)
                .moveUpToKeyboard(false)
                .isRequestFocus(false)
                .hasShadowBg(false)
                .hasStatusBarShadow(false)
                .asCustom(dtoHClientinfoPp);//定转活 选择转化数据；
        surePrintPop = new SurePrintPopup(this, this, this);
        //打印纸是否正常界面
        surePrintPopupView = new XPopup.Builder(this)
                .dismissOnBackPressed(false)
                .dismissOnTouchOutside(false)
                .moveUpToKeyboard(false)
                .isRequestFocus(false)
                .hasShadowBg(false)
                .hasStatusBarShadow(false)
                .asCustom(surePrintPop);
        printingPop = new PrintingPopup(this, this);
        //打印中界面
        printingPopupView = new XPopup.Builder(this)
                .dismissOnBackPressed(false)
                .dismissOnTouchOutside(false)
                .moveUpToKeyboard(false)
                .isRequestFocus(false)
                .hasShadowBg(false)
                .hasStatusBarShadow(false)
                .asCustom(printingPop);
        htoDSuccessPp = new HtoDSuccessPp(this, this);
        htoDSuccessPpView = new XPopup.Builder(this)
                .dismissOnBackPressed(false)
                .dismissOnTouchOutside(false)
                .moveUpToKeyboard(false)
                .isRequestFocus(false)
                .hasShadowBg(false)
                .hasStatusBarShadow(false)
                .asCustom(htoDSuccessPp);
        dealingPop = new DealingPopup(this, this);
        dealingPopupView = new XPopup.Builder(this)
                .dismissOnBackPressed(false)
                .dismissOnTouchOutside(false)
                .moveUpToKeyboard(false)
                .isRequestFocus(false)
                .hasShadowBg(false)
                .hasStatusBarShadow(false)
                .asCustom(dealingPop);


        selHtoDSaveTypePp = new SelHtoDSaveTypePp(this, this);
        //活转定选择类型
        selHtoDSaveTypePpView = new XPopup.Builder(this)
                .dismissOnBackPressed(false)
                .dismissOnTouchOutside(false)
                .moveUpToKeyboard(false)
                .isRequestFocus(false)
                .hasShadowBg(false)
                .hasStatusBarShadow(false)
                .asCustom(selHtoDSaveTypePp);
        readcardPop = new ReadCardPopup(this);
        readcardPopupView = new XPopup.Builder(this)
                .dismissOnBackPressed(false)
                .dismissOnTouchOutside(false)
                .moveUpToKeyboard(false)
                .isRequestFocus(false)
                .hasShadowBg(false)
                .hasStatusBarShadow(false)
                .asCustom(readcardPop);//验证账户信息界面

        verifycardPop = new VerifyCardPopup(this, this);
        verifycardPopupView = new XPopup.Builder(this)
                .dismissOnBackPressed(false)
                .dismissOnTouchOutside(false)
                .moveUpToKeyboard(false)
                .isRequestFocus(false)
                .hasShadowBg(false)
                .hasStatusBarShadow(false)
                .asCustom(verifycardPop);//验证账户信息界面
        inputpasswordPop = new InputPasswordPopup(this, this);
        inputpasswordPopupView = new XPopup.Builder(this)
                .dismissOnBackPressed(false)
                .dismissOnTouchOutside(false)
                .moveUpToKeyboard(false)
                .isRequestFocus(false)
                .hasShadowBg(false)
                .hasStatusBarShadow(false)
                .asCustom(inputpasswordPop);//输入密码界面
    }

    @Override
    public void initEvent(Bundle savedInstanceState) {

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }

    @OnClick({R.id.live_to_atfixedperiod_btn, R.id.atfixedperiod_to_live_btn})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.live_to_atfixedperiod_btn:
                //活转定
                homeCardLayout.setVisibility(View.GONE);

                readcardtwstart();//读卡操作
                break;
            case R.id.atfixedperiod_to_live_btn:
                HtoD = false;
                //定转活
                homeCardLayout.setVisibility(View.GONE);
                readcardtwstart();
                break;
        }

    }


    /**
     * 读卡带密码键盘
     */
    private void readcardtwstart() {
        tradeWithCards(new HttpUtils.BaseReadCardTwListener() {


            @Override
            public void onSuccess(String data, String track2Datas, String pin) {

                card_num = data;
                track2Data = track2Datas;

                cipassword = pin;
                verifycardPopupView.show();
                HttpUtilsV2.getCheckingThisBank(data, new HttpUtilsV2.NetCallBack() {
                    @Override
                    public void onSuccess(String ServerSeqNo, String ConsumerSeqNo, JSONObject rspBody) {
                        runOnUiThread(() -> {
                            verifycardPopupView.dismiss();
                            doTrBank();
                        });
                    }

                    @Override
                    public void onError(String code, String msg) {
                        showErr(msg);
                    }
                });
            }

            @Override
            public void onError(String msg) {

            }
        });
    }


    private void showErr(String msg) {
        runOnUiThread(() -> {
            errorPopup.setMsg(msg);
            errorPopupPpView.show();
        });
    }

    /**
     * 输入密码的回调
     *
     * @param password
     */
    @Override
    public void SendPassword(String password) {
        KLog.e("密码加密");
        KLog.e(password + "card_num" + card_num);
        cipassword = HttpUtils.getResult(password, card_num);
        inputpasswordPopupView.dismiss();
        doTrBank();
    }

    /**
     * 业务
     */
    private void doTrBank() {
        //弹出验证消息
        showMakeHint("验证密码...");
        HttpUtilsV2.getAccountPwdVerification(card_num, cipassword, new HttpUtilsV2.NetCallBack() {


            @Override
            public void onSuccess(String ServerSeqNo, String ConsumerSeqNo, JSONObject rspBody) {
                runOnUiThread(() -> {
                    //验证密码成功
                    dismissshowMakeHint();
                    //获取客户信息
                    showMakeHint("获取客户信息...");
                    HttpUtilsV2.getQueryBankCardInfo(card_num, new HttpUtilsV2.NetCallBack() {
                        @Override
                        public void onSuccess(String ServerSeqNo, String ConsumerSeqNo, JSONObject rspBody) {
                            card_username = rspBody.getString("AcctName");
                            certNo = rspBody.getString("CertNo");
                            certType = rspBody.getString("CertType");
                            userBalance = rspBody.getString("AvlBalance");
                            runOnUiThread(() -> {
                                dismissshowMakeHint();
                                showMakeHint("黑名单验证...");
                                HttpUtilsV2.getCheckingBankCardBlacklist(card_num, card_username, new HttpUtilsV2.NetCallBack() {
                                    @Override
                                    public void onSuccess(String ServerSeqNo, String ConsumerSeqNo, JSONObject rspBody) {
                                        runOnUiThread(() -> {
                                            dismissshowMakeHint();
                                            //黑名单验证通过
                                            if (HtoD) {
                                                //如果是活转定
                                                dismissshowMakeHint();
                                                selHtoDSaveTypePpView.show();
                                            } else {
                                                //如果是定转活
                                                //子账户查询中
                                                showMakeHint("子账户查询中...");
                                                HttpUtilsV2.getSubAccountInformationQuery(card_num,
                                                        cipassword,
                                                        "0",
                                                        new HttpUtilsV2.NetCallBack() {
                                                            @Override
                                                            public void onSuccess(String ServerSeqNo, String ConsumerSeqNo, JSONObject rspBody) {
                                                                String zzhBeanstr = rspBody.getString("FS_PDT_GRP");

                                                                Gson gson = new Gson();

                                                                zzhBeans = gson.fromJson(zzhBeanstr, new TypeToken<ArrayList<ZzhBean>>() {
                                                                }.getType());
                                                                zzhBeans.remove(0);

                                                                newzzhBeans = new ArrayList<>();

                                                                for (int i = 0; i < zzhBeans.size(); i++) {
                                                                    if (!zzhBeans.get(i).getFS_ACCT_BAL().equals("000000000000000")) {
                                                                        newzzhBeans.add(zzhBeans.get(i));
                                                                    }
                                                                }
                                                                runOnUiThread(() -> {
                                                                    dismissshowMakeHint();
                                                                    dtoHClientinfoPp.setZzhBeans(newzzhBeans);
                                                                    dtoHClientinfoPpView.show();
                                                                });
                                                            }

                                                            @Override
                                                            public void onError(String code, String msg) {
                                                                showErr(msg);
                                                            }
                                                        });
                                            }
                                        });
                                    }

                                    @Override
                                    public void onError(String code, String msg) {

                                    }
                                });
                            });
                        }

                        @Override
                        public void onError(String code, String msg) {

                        }
                    });
                });
            }

            @Override
            public void onError(String code, String msg) {
                runOnUiThread(() -> {
                    ToastUtils.showLong(msg);
                    finish();
                });
            }
        });

    }


    /**
     * 活转定选择类型返回
     */
    @Override
    public void SelType(String type) {
        SAVE_TYPE = type;
        if (selHtoDSaveTypePpView.isShow()) {
            selHtoDSaveTypePpView.dismiss();
        }


        selHtoDSaveTimePp = new SelHtoDSaveTimePp(this, this, this);
        selHtoDSaveTimePpView = new XPopup.Builder(this)
                .dismissOnBackPressed(false)
                .dismissOnTouchOutside(false)
                .moveUpToKeyboard(false)
                .isRequestFocus(false)
                .hasShadowBg(false)
                .hasStatusBarShadow(false)
                .asCustom(selHtoDSaveTimePp);
        selHtoDSaveTimePp.setUserBal(userBalance);
        selHtoDSaveTimePpView.show();
    }


    /**
     * 选择活转定数据返回
     * ProductCode 理财标志
     * time 存期
     * money 金额
     * rateOfInterest 利率
     * interest 利息
     * total 合计
     * unlading 自动转存
     * unloadingtype 自动转存类型
     */
    @Override
    public void HtDinfo(String ProductCode, String time, String money, String rateOfInterest, String interest,
                        String total, String name, boolean unlading, String unloadingtype) {
        sureHtoDInfoPp = null;
        sureHtoDInfoPpView = null;
        sureHtoDInfoPp = new SureHtoDInfoPp(this, this);
        sureHtoDInfoPpView = new XPopup.Builder(this)
                .dismissOnBackPressed(false)
                .dismissOnTouchOutside(false)
                .moveUpToKeyboard(false)
                .isRequestFocus(false)
                .hasShadowBg(false)
                .hasStatusBarShadow(false)
                .asCustom(sureHtoDInfoPp);


        htodProductCode = ProductCode;
        htodtime = time;
        htodMoney = money;
        htodrateOfInterest = rateOfInterest;
        htodinterest = interest;
        htodtotal = total;
        htodZcTag = unloadingtype;
        htodName = name;
        selHtoDSaveTypePpView.dismiss();
        sureHtoDInfoPp.setmBankNum(card_num); //卡号

        sureHtoDInfoPp.setmInterest(htodinterest);//利息
        sureHtoDInfoPp.setmMoney(GetMoneyLvUtils.getInputMoney(htodMoney));//金额
        sureHtoDInfoPp.setmPNmae(name);//产品名
        sureHtoDInfoPp.setmRateOfInterest(htodrateOfInterest);//利率
        if (!unlading) {
            htodTag = "不自动转存";
            sureHtoDInfoPp.setmTag("不自动转存");//转存标志

        } else {
            if (unloadingtype.equals(BJ)) {
                htodTag = "本金转存";
                sureHtoDInfoPp.setmTag("本金转存");//转存标志
            } else {
                htodTag = "本息转存";
                sureHtoDInfoPp.setmTag("本息转存");//转存标志
            }
        }
        sureHtoDInfoPp.setmTime(time);//存储时间
        sureHtoDInfoPp.setmUsername(card_username);//用户名

        selHtoDSaveTimePpView.dismiss();
        sureHtoDInfoPpView.show();
    }

    /**
     * 确认活转定信息 确定
     */
    @Override
    public void HtoDNext() {
        sureHtoDInfoPpView.dismiss();
        dealingPopupView.show();
        KLog.e(htodtime);
        String time = "";
        if (htodtime.equals("三个月")) {
            time = "00090";
        } else if (htodtime.equals("六个月")) {
            time = "00180";
        } else if (htodtime.equals("一年")) {
            time = "00360";
        } else if (htodtime.equals("两年")) {
            time = "00720";
        } else if (htodtime.equals("三年")) {
            time = "01080";
        } else if (htodtime.equals("五年")) {
            time = "01800";
        }
        KLog.e(time);

        String ProductCode = "0";
        String TFT_TD_INT_ACCT_NO = "";
        if (!htodZcTag.equals("")) {
            ProductCode = "1";
            if (htodZcTag.equals(BJ)) {
                TFT_TD_INT_ACCT_NO = card_num;
            }
        }
        make_time = TimeUtils.getTimeData();
        HttpUtilsV2.getCurrentTransfer(
                "1",
                card_num,
                cipassword,
                "1",
                htodMoney,
                time,
                "11",
                "0102",
                track2Data,
                "0101",
                htodProductCode,
                ProductCode,
                "",
                TFT_TD_INT_ACCT_NO,
                new HttpUtilsV2.NetCallBack() {


                    @Override
                    public void onSuccess(String ServerSeqNo, String ConsumerSeqNo, JSONObject rspBody) {
                        runOnUiThread(() -> {
                            mServerSeqNo = ServerSeqNo;
                            htodPenNum = rspBody.getString("SEQ_NO_N");
                            htodEndTime = rspBody.getString("DEP_DUE_DT");
                            dealingPopupView.dismiss();
                            htoDSuccessPp.setmBanknum(card_num);
                            htoDSuccessPp.setmName("活期转定期");
                            htoDSuccessPp.setmMoney(GetMoneyLvUtils.getInputMoney(htodMoney));
                            htoDSuccessPp.setmUserName(card_username);
                            htoDSuccessPp.setmType(htodName);
                            htoDSuccessPpView.show();
                        });

                    }

                    @Override
                    public void onError(String code, String msg) {
                        showErr(msg);
                    }
                }
        );
    }

    /**
     * 确认活转定信息 上一步
     */
    @Override
    public void HtoDLastStep() {
        sureHtoDInfoPpView.dismiss();
        selHtoDSaveTimePp = null;
        selHtoDSaveTimePpView = null;
        selHtoDSaveTimePp = new SelHtoDSaveTimePp(this, this, this);
        selHtoDSaveTimePpView = new XPopup.Builder(this)
                .dismissOnBackPressed(false)
                .dismissOnTouchOutside(false)
                .moveUpToKeyboard(false)
                .isRequestFocus(false)
                .hasShadowBg(false)
                .hasStatusBarShadow(false)
                .asCustom(selHtoDSaveTimePp);
        selHtoDSaveTimePp.setUserBal(userBalance);
        selHtoDSaveTimePpView.show();
    }

    /**
     * 活转定 成功
     */
    @Override
    public void HtoDSuccessPrint() {
        htoDSuccessPpView.dismiss();
        surePrintPopupView.show();
    }

    /**
     * 确认打印
     */
    @Override
    public void ToPrint() {
        surePrintPopupView.dismiss();
        printingPopupView.show();
        //请求电子印章
        HttpUtilsV2.getElectronicSeal("1", new HttpUtilsV2.NetCallBack() {
            @Override
            public void onSuccess(String ServerSeqNo, String ConsumerSeqNo, JSONObject rspBody) {
                runOnUiThread(() -> {
                    if (HtoD) {

                        PrintUtil.CurrentTrapezium(PosFuncs.getInstace(),
                                make_time
                                , "活期转定期"
                                , mServerSeqNo
                                , htodPenNum
                                , card_username
                                , card_num
                                , htodName
                                , htodtime
                                , GetMoneyLvUtils.gettimeNohour(htodEndTime)
                                , htodrateOfInterest
                                , htodMoney
                                , htodTag
                                , htodinterest
                                , rspBody.getString("ImgBase64"),
                                new PrintUtil.onPrintinterface() {
                                    @Override
                                    public void success(String success) {
                                        PrintUtil.CurrentTrapezium2(PosFuncs.getInstace(),
                                                make_time
                                                , "活期转定期"
                                                , mServerSeqNo
                                                , htodPenNum
                                                , card_username
                                                , card_num
                                                , htodName
                                                , htodtime
                                                , GetMoneyLvUtils.gettimeNohour(htodEndTime)
                                                , htodrateOfInterest
                                                , htodMoney
                                                , htodTag
                                                , htodinterest
                                                , rspBody.getString("ImgBase64"),
                                                new PrintUtil.onPrintinterface() {
                                                    @Override
                                                    public void success(String success) {
                                                        SPStaticUtils.put("ccsno", SPStaticUtils.getInt("ccsno", 1) + 1);
                                                        ToastUtils.showLong(success);
                                                        finish();
                                                    }

                                                    @Override
                                                    public void failed(String error) {
                                                        showErr(error);

                                                    }
                                                });
                                    }

                                    @Override
                                    public void failed(String error) {
                                        showErr(error);

                                    }
                                });


                    } else {
                        PrintUtil.printCurrentDeposit(PosFuncs.getInstace(),
                                make_time,
                                "定期转活期",
                                mServerSeqNo
                                , returnzzhBean1.getFS_SEQ_NO().trim(),
                                card_username,
                                card_num,
                                returnzzhBean1.getPDP_SHORT_NAME(),
                                GetMoneyLvUtils.getLv(returnzzhBean1.getFS_INTR()),
                                returnzzhBean1.getFS_TRAN_TYP(),
                                GetMoneyLvUtils.gettimeNohour(returnzzhBean1.getFS_DUE_DT().trim()),
                                GetMoneyLvUtils.gettimeNohour(returnzzhBean1.getFS_OPAC_DT().trim()),
                                dtoHmoneys,
                                accBal,
                                GetMoneyLvUtils.getMoney(intInt),
                                rspBody.getString("ImgBase64"),
                                new PrintUtil.onPrintinterface() {
                                    @Override
                                    public void success(String success) {
                                        PrintUtil.printCurrentDeposit2(PosFuncs.getInstace(), make_time, "定期转活期", mServerSeqNo
                                                , returnzzhBean1.getFS_SEQ_NO().trim(), card_username, card_num, returnzzhBean1.getPDP_SHORT_NAME(),
                                                GetMoneyLvUtils.getLv(returnzzhBean1.getFS_INTR()), returnzzhBean1.getFS_TRAN_TYP(),
                                                GetMoneyLvUtils.gettimeNohour(returnzzhBean1.getFS_DUE_DT().trim()),
                                                GetMoneyLvUtils.gettimeNohour(returnzzhBean1.getFS_OPAC_DT().trim()),
                                                dtoHmoneys,
                                                accBal,
                                                GetMoneyLvUtils.getMoney(intInt),
                                                rspBody.getString("ImgBase64"),
                                                new PrintUtil.onPrintinterface() {
                                                    @Override
                                                    public void success(String success) {
                                                        SPStaticUtils.put("ccsno", SPStaticUtils.getInt("ccsno", 1) + 1);
                                                        finish();
                                                    }

                                                    @Override
                                                    public void failed(String error) {
                                                        showErr(error);
                                                    }
                                                });
                                    }

                                    @Override
                                    public void failed(String error) {
                                        showErr(error);
                                    }
                                }

                        );
                    }
                });
            }

            @Override
            public void onError(String code, String msg) {
                showErr(msg);
            }
        });

    }


    /**
     * 定转活 确定数据 下一步
     */
    @Override
    public void SureDtoHNext() {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle("提示");
        builder.setMessage("您的存款未到期，提前支取可能达不到预期收益，是否继续");
        builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {


            @Override
            public void onClick(DialogInterface dialog, int which) {
                sureDtoHinfoPpView.dismiss();
                dealingPopupView.show();
                //获取交易时间
                make_time = TimeUtils.getTimeData();
                HttpUtilsV2.getFixedTurns(
                        card_num,
                        dtoHmoneys,
                        cipassword,
                        "",
                        pdp_codEs,
                        seq_nOs,
                        certType,
                        certNo,
                        card_username,
                        new HttpUtilsV2.NetCallBack() {
                            @Override
                            public void onSuccess(String ServerSeqNo, String ConsumerSeqNo, JSONObject rspBody) {
                                mServerSeqNo = ServerSeqNo;

                                runOnUiThread(new Runnable() {
                                    @Override
                                    public void run() {
                                        dealingPopupView.dismiss();
                                        dtohSuccessPp.setmBanknum(card_num);
                                        dtohSuccessPp.setmUserName(card_username);
                                        dtohSuccessPp.setmType("定期转活期");
                                        dtohSuccessPp.setmMoney(dtoHmoneys);
                                        intInt = rspBody.getString("INT");
                                        dtohSuccessPpView.show();
                                    }
                                });
                            }

                            @Override
                            public void onError(String code, String msg) {
                                showErr(msg);
                            }
                        });


            }
        });

        builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                finish();
            }
        });

        builder.show();
    }

    /**
     * 定转活成功 打印按钮
     */
    @Override
    public void DtoHSuccessPrint() {
        dtohSuccessPpView.dismiss();
        surePrintPopupView.show();
    }

    /**
     * 错误提示
     */
    @Override
    public void finished() {
        finish();
    }

    @Override
    public void ClientInputCall(String money, ZzhBean zzhBean) {
        dtoHClientInputMoneyPpView.dismiss();
        returnzzhBean1 = zzhBean;
        pdp_codEs = zzhBean.getFS_PDP_CODE();
        seq_nOs = zzhBean.getFS_SEQ_NO();

        //获取返回数据


        if (sureDtoHinfoPp != null) {
            sureDtoHinfoPp = null;
        }
        if (sureDtoHinfoPpView != null) {
            sureDtoHinfoPpView = null;
        }
        sureDtoHinfoPp = new SureDtoHinfoPp(this, this);
        //定转活确定数据界面
        sureDtoHinfoPpView = new XPopup.Builder(this)
                .dismissOnBackPressed(false)
                .dismissOnTouchOutside(false)
                .moveUpToKeyboard(false)
                .isRequestFocus(false)
                .hasShadowBg(false)
                .hasStatusBarShadow(false)
                .asCustom(sureDtoHinfoPp);//确定定转活信息

        sureDtoHinfoPp.setSureSwitchinfoTypes("定期转活期");
        sureDtoHinfoPp.setSureSwitchinfoNumtexts(card_num);
        sureDtoHinfoPp.setSureUsernames(card_username);
        sureDtoHinfoPp.setSurePennums(zzhBean.getFS_SEQ_NO().trim());
        sureDtoHinfoPp.setSureSwitchinfoNames(zzhBean.getSA_PDP_NAME().trim());
        sureDtoHinfoPp.setSureIns(GetMoneyLvUtils.getLv(zzhBean.getFS_INTR()));
        sureDtoHinfoPp.setFS_MNG_FLG(zzhBean.getFS_MNG_FLG());
        sureDtoHinfoPp.setSureTotags(zzhBean.getFS_TRAN_TYP());

        sureDtoHinfoPp.setSureSwitchinfoValuedates(GetMoneyLvUtils.gettimeNohour(zzhBean.getFS_VAL_DT()));
        sureDtoHinfoPp.setSureEndtimes(GetMoneyLvUtils.gettimeNohour(zzhBean.getFS_DUE_DT().trim()));
        if (zzhBean.getFS_ACCT_BAL().equals("000000000000000")) {
            sureDtoHinfoPp.setSureSwitchinfoMoneytexts("0.00");
        } else {
            sureDtoHinfoPp.setSureSwitchinfoMoneytexts(GetMoneyLvUtils.getMoney(zzhBean.getFS_ACCT_BAL()));
        }


        if (money.equals(zzhBean.getFS_ACCT_BAL())) {
            dtoHClientinfoPpView.dismiss();
            sureDtoHinfoPp.setSureSwitchinfoGetmoneys(GetMoneyLvUtils.getMoney(zzhBean.getFS_ACCT_BAL()));
            sureDtoHinfoPp.setSureSwitchinfoGettags("全部支取");
            sureDtoHinfoPp.setSureSwitchinfoGetawaymoneys("0.00");
            sureDtoHinfoPpView.show();
            //支取金额   取开户金额
            dtoHmoneys = GetMoneyLvUtils.getMoney(zzhBean.getFS_OPAC_AMT());
            accBal = "0.00";
        } else {
            sureDtoHinfoPp.setSureSwitchinfoGettags("部分支取");

//            部分提取用开户金额控制  输入的金额不能超过开户金额
            Double allm = Double.valueOf(GetMoneyLvUtils.getMoney(zzhBean.getFS_OPAC_AMT()));
            //提取金额
            Double mm;
            DecimalFormat myformat = new DecimalFormat("#0.00");
            mm = Double.parseDouble(money);//装换为double类型
            mm = Double.parseDouble(myformat.format(mm));//保留小数
            KLog.e(mm + "mm");
            if (mm > allm) {
                ToastUtils.showLong("支取金额大于开户金额");
            } else {
                dtoHClientinfoPpView.dismiss();
                //支取后剩余的金额
                Double sm = (allm - mm);
                KLog.e(sm + "sm");
                //支取金额
                sureDtoHinfoPp.setSureSwitchinfoGetmoneys(String.valueOf(mm));
                //支取后剩余金额
                sureDtoHinfoPp.setSureSwitchinfoGetawaymoneys(String.valueOf(sm));
                sureDtoHinfoPpView.show();
                accBal = String.valueOf(sm);
                //支取金额
                dtoHmoneys = String.valueOf(mm);
                KLog.e("支取金额" + dtoHmoneys);
            }
        }
    }

    @Override
    public void ClientupNext() {
        dtoHClientInputMoneyPp.dismiss();
        dtoHClientinfoPp = null;
        dtoHClientinfoPpView = null;
        dtoHClientinfoPp = new DtoHClientinfoPp(this, this);
        dtoHClientinfoPp.setZzhBeans(newzzhBeans);
        dtoHClientinfoPpView = new XPopup.Builder(this)
                .dismissOnBackPressed(false)
                .dismissOnTouchOutside(false)
                .moveUpToKeyboard(false)
                .isRequestFocus(false)
                .hasShadowBg(false)
                .hasStatusBarShadow(false)
                .asCustom(dtoHClientinfoPp);//定转活 选择转化数据；
        dtoHClientinfoPpView.show();
    }

    /**
     * 选择了子账户
     */
    @Override
    public void SelDtoHData(ZzhBean zzhBean) {

        if (dtoHClientInputMoneyPp != null) {
            dtoHClientInputMoneyPp = null;
            dtoHClientInputMoneyPpView = null;
        }


        dtoHClientInputMoneyPp = new DtoHClientInputMoneyPp(this, this);
        //确定定转活信息
        dtoHClientInputMoneyPpView = new XPopup.Builder(this)
                .dismissOnBackPressed(false)
                .dismissOnTouchOutside(false)
                .moveUpToKeyboard(false)
                .isRequestFocus(false)
                .hasShadowBg(false)
                .hasStatusBarShadow(false)
                .asCustom(dtoHClientInputMoneyPp);

        dtoHClientInputMoneyPp.setSureSwitchinfoTypes("定期转活期");
        dtoHClientInputMoneyPp.setSureSwitchinfoNumtexts(card_num);
        dtoHClientInputMoneyPp.setSureUsernames(card_username);
        dtoHClientInputMoneyPp.setSurePennums(zzhBean.getFS_SEQ_NO().trim());
        dtoHClientInputMoneyPp.setSureSwitchinfoNames(zzhBean.getSA_PDP_NAME().trim());
        dtoHClientInputMoneyPp.setSureIns(GetMoneyLvUtils.getLv(zzhBean.getFS_INTR()));
        dtoHClientInputMoneyPp.setSureTotags(zzhBean.getFS_TRAN_TYP());
        dtoHClientInputMoneyPp.setFS_MNG_FLG(zzhBean.getFS_MNG_FLG());

        dtoHClientInputMoneyPp.setSureSwitchinfoValuedates(GetMoneyLvUtils.gettimeNohour(zzhBean.getFS_VAL_DT()));
        dtoHClientInputMoneyPp.setSureEndtimes(GetMoneyLvUtils.gettimeNohour(zzhBean.getFS_DUE_DT().trim()));
        if (zzhBean.getFS_ACCT_BAL().equals("000000000000000")) {
            dtoHClientInputMoneyPp.setSureSwitchinfoMoneytexts("0.00");
        } else {
            dtoHClientInputMoneyPp.setSureSwitchinfoMoneytexts(GetMoneyLvUtils.getMoney(zzhBean.getFS_ACCT_BAL()));
        }
        dtoHClientInputMoneyPp.setZzhBean(zzhBean);
        dtoHClientInputMoneyPpView.show();
    }


}
